package com.toobigtofail
{
	import net.flashpunk.FP;
	import net.flashpunk.World;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	
	public class Game extends World
	{
		public var sceneManager:SceneManager = new SceneManager();
		private var _state:String = "intro";
		private var _elapsed:Number = 0;
		private var _stepComplete:Array = [];
		private const _GAME_LENGTH:Number = 300;
		
		public const TITLE:String = "Last Day";
		
		public function Game()
		{
			super();
		}
		
		override public function begin():void
		{
			_state = "intro";
			FP.console.watch(_state);
			add(sceneManager);
			super.begin();
		}
		
		override public function update():void
		{
			super.update();
			_elapsed += FP.elapsed;
			
			switch(_state)
			{
				case "intro": updateIntro(); break;
				case "playing": updatePlaying(); break;
				case "outro": updateOutro(); break;
				
			}
		}
		
		private function updateIntro():void
		{
			if(_elapsed > 3 && _stepComplete.length == 0)
			{
				_stepComplete.push(true);
				sceneManager.addScene(new Scene(9,14,23,90,0xDD3311));
				sceneManager.addScene(new Scene(400,20,380,560,0x000000,TITLE));
				
			}
			
			
		}
		
		private function updatePlaying():void
		{	
			if (_elapsed >= _GAME_LENGTH)
			{
				_elapsed = 0;
				_state = "outro";
			}
			if(Input.check(Key.X))
				sceneManager.clearScenes();
		}
		
		private function updateOutro():void
		{
			
		}
	}
}